﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Drawing;
using System.Drawing.Imaging;

namespace CivilleWebRole
{
    public partial class EditStakeholder : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e) 
        {
            if (!User.Identity.IsAuthenticated)
            {
                Response.Redirect("~/NotAuthorized.aspx");
            }

            String connectionString = ConfigurationManager.ConnectionStrings["CivilleConnectionString"].ConnectionString;
            SqlConnection connection = new SqlConnection(connectionString);
            SqlCommand command = connection.CreateCommand();
            command.CommandText = "SELECT * FROM Stakeholder WHERE Name = '" + User.Identity.Name + "'";
            connection.Open();
          //  Stakeholder stakeholder = (Stakeholder) command.ExecuteScalar();
            SqlDataReader reader = command.ExecuteReader();
            List<String> stakeholders = new List<String>();
            while (reader.Read())
            {
                stakeholders.Add(reader[0].ToString());
            }
            reader.Close();
            connection.Close();
            NameTxt.Text = User.Identity.Name;
        }

        protected void SaveAccountButtonClick(object sender, EventArgs e)
        {
            String connectionString = ConfigurationManager.ConnectionStrings["CivilleConnectionString"].ConnectionString;
            SqlConnection connection = new SqlConnection(connectionString);
            SqlCommand command = connection.CreateCommand();
            command.CommandText = "INSERT INTO [Stakeholder] ([Name], [BusinessType], [Description], [Latitude], [Longitude], [Website], [Facebook], [Logo]) VALUES ('" + NameTxt.Text + "', '" + BusinessTypeDDL.SelectedValue + "', '" + DescriptionTxt.Text + "', '" + LatitudeTxt.Text + "', '" + LongitudeTxt.Text + "', '" + SiteTxt.Text + "', '" + FacebookTxt.Text + "', '" + EmailTxt.Text + "', '" + FileUpload.FileName + "')";
            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
        }
    }
}